/**
 * 腾讯 cos 文件存储方法类封装
 */
import bcrypt from 'bcryptjs';

const SALT_WORK_FACTOR = 10;

/**
 * 将密码转化成 hash 字符串
 * @param password 密码
 * @returns hash 字符串
 */
export function transPasswordToHash(password: string = '') {
  const salt = bcrypt.genSaltSync(SALT_WORK_FACTOR);
  const result = bcrypt.hashSync(password, salt);
  return result;
}

/**
 * 对比密码是否相同
 * @param trueStr 密码 hash 字符串
 * @param hash 密码
 * @returns true/false
 */
export function comparePassword(trueStr: string = '', hash: string = '') {
  const result = bcrypt.compareSync(trueStr, hash);
  return result;
}
